function loader(source) {
  const reg = /url\((.+?)\)/g
  let pos = 0
  let current
  let arr = ['let list = []']
  while (reg.exec(source)) {
    let [matchUrl, g] = current
    let last = reg.lastIndex - matchUrl.length
    arr.push(`list.push(${ JSON.stringify(source.slice(pos, last))})`)
    arr.push(`list.push('url(' + require(${g}) + ')')`)
  }
  arr.push(`list.push(${ JSON.stringify(source.slice(pos))})`)
  arr.push(`module.exports = list.join('')`)
  return arr.join('\r\n')
}

module.exports = loader
